package spring.exam.control; 

import javax.validation.*;

import org.springframework.stereotype.*;
import org.springframework.ui.ModelMap;
import org.springframework.validation.*;
import org.springframework.web.bind.annotation.*; 
import org.springframework.web.servlet.config.annotation.*; 

import spring.exam.hello.Person;


@Controller
public class FromDemoController extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/results").setViewName("results");
    }

    @RequestMapping(value="/formDemo.con", method=RequestMethod.GET)
    public String showForm(Person person) {
        return "formDemo.html";
    }

    @RequestMapping(value="/formDemo.con", method=RequestMethod.POST)
    public String checkPersonInfo(@Valid Person person, BindingResult bindingResult, final ModelMap model) {
        if (bindingResult.hasErrors()) {
            return "formDemo.html";
        } else {
        
        	model.addAttribute( "svrMsg", "저장 성공" );
        	return "formDemo.html";
        }
    }

}